//工单编号
var gdbh = getQueryString("gdbh");
$(function () {
    $("#jqGrid").Grid({
        url: '../sparestorepos/list?lowestNum=1',
        rownumWidth: 50,
        colModel: [
            {label: '备件名称', name: 'spareName', index: 'spareName', width: 80},
            {label: '备件规格', name: 'spec', index: 'spec', width: 80},
            {label: '备件编码', name: 'spareCode', index: 'SPARE_CODE', width: 60},
            {label: 'ERP编码', name: 'erpCode', index: 'SPARE_CODE', width: 60},
            {label: '供应厂商', name: 'producerName', width: 60},
            {label: '仓库名称', name: 'storeName', width: 120},
            {label: '库位', name: 'postion', index: 'POSTION', width: 60},
            {label: '库存数', name: 'storeNum', index: 'STORE_NUM', width: 40},
            // {
            //     label: '操作', width: 80, align: 'center', sortable: false, formatter: function (value, col, row) {
            //         return "<button class='btn btn-outline btn-info' onclick='vm.detailsInfo(\"" + row.spareCode + "\")'><i class='fa fa-info-circle'></i>&nbsp;库房详情</button>";
            //
            //     }
            // },
            {label: 'id', name: 'id', key: true, hidden: true},
            {label: '锁定数', name: 'locNum', hidden: true},
            {label: '备件ID', name: 'spareId', hidden: true},
            {label: 'storeId', name: 'storeId', hidden: true},
        ]
    });
});

var vm = new Vue({
    el: '#rrapp',
    data: {
        showList: true,
        title: null,
        sparePartOut: {
            delFlag: 1,
            remark: '',
            useDevId: '',
            useDevName: '',
            useDevCode: '',
            pickNoId: '',
            pickNo: '',
            repairNoId: '',
            repairNo: '',
            backNum: '',
            outNum: '',
            cargoLocation: '',
            partUnit: '',
            spec: '',
            name: '',
            partCode: '',
            outStoreId: '',
            outStore: '',
            useUnit: '',
            outDate: new Date(),
            outCode: '',
            id: '',
            checkDate: '',
            checkStatus: '1', //未审核
            checkUser: '',
            updateDate: '',
            updateUser: '',
            createUser: '',
            createDate: '',
            devTypeName: '',
            devType: ''
        },
        q: {
            partName: '', // 备件名称
            spec: '', // 备件规格
            partCode: '', // 备件编码
            erpCode: '', // ERP编码
            producor:'', // 供应厂家
            storeId:'', // 所在仓库ID
            storeType: '' //仓库类别：1：ERP库 2:线边库
        },
        typeList:enumsToList('SPARE_TYPE'),
        resourcesList: enumsToList('RESOURCES_TYPE')
    },

    methods: {
        query: function () {
            vm.reload();
        },
        reload: function (event) {
            vm.showList = true;
            var page = $("#jqGrid").jqGrid('getGridParam', 'page');
            $("#jqGrid").jqGrid('setGridParam', {
                postData: vm.q,
                page: page
            }).trigger("reloadGrid");
            vm.handleReset('formValidate');
        },
        reloadSearch: function () {
            vm.q = {
                partName: '', // 备件名称
                spec: '', // 备件规格
                partCode: '', // 备件编码
                erpCode: '', // ERP编码
                producor:'', // 供应厂家
                storeId:'', // 所在仓库ID
                storeType: ''
            };
            vm.reload();
        },
        handleSubmit: function (name) {
            handleSubmitValidate(this, name, function () {
                vm.saveOrUpdate()
            });
        },
        handleReset: function (name) {
            handleResetForm(this, name);
        },

    }
});

var getSpareStroe = function () {
    let result = getSelectedRowData("#jqGrid");
    var id = result.id;
    if (id == null) {
        return false;
    } else {
        return result;
    }
}
